package main

import (
	"fmt"
	"strconv"
	"strings"
)

/**
 * @author: guangcheng
 * @date:   2020/11/9 20:12
 * @version  V1.0
 * @description:
		init()...execute...
		main()...execute...
 *
*/
func init() {
	//在main()之前执行, 做一些初始化操作
	fmt.Println("init()...execute...")

}
func main() {

	fmt.Println("main()...execute...")

	//整数转字符串
	str := strconv.Itoa(123)
	fmt.Printf("str=%v strType=%T\n", str, str)

	//str=123 strType=string
	var bytes = []byte("hello go")
	//bytes=[104 101 108 108 111 32 103 111]
	fmt.Printf("bytes=%v\n", bytes)

	//str=abc strType=string
	str = string([]byte{97, 98, 99})
	fmt.Printf("str=%v strType=%T", str, str)

	bool01 := strings.Contains("hellosuguan", "suguan")
	fmt.Println("\n", bool01)

	count := strings.Count("chesseessee", "e")
	fmt.Println(count)

	//不区分大小写
	bool02 := strings.EqualFold("abc", "AbC")
	fmt.Println(bool02)

	fmt.Println("区分大小写:", "abc" == "Abc")

	//返回子串在母串中第一次出现的位置, 没有则返回 -1
	index := strings.Index("NLT_abc", "hello")
	index1 := strings.Index("NLT_abc", "T")
	//-1 2
	fmt.Println(index, index1)

	//指定替换字符串的部分, -1: 替换全部出现的指定部分
	str = "go go go jva and go"
	strRe := strings.Replace(str, "go", "beijing", -1)
	fmt.Println("str=", str, "strRe=", strRe)

	splitArr := strings.Split("hello,java,go", ",")
	//splitArr=[hello java go] splitArrType=[]string
	fmt.Printf("splitArr=%v splitArrType=%T", splitArr, splitArr)
	fmt.Println()
	for i := range splitArr {
		//hello
		//java
		//go
		fmt.Println(splitArr[i])
	}
	for i, s := range splitArr {
		//hello hello
		//java java
		//go go
		fmt.Println(splitArr[i], s)
	}

	str = "! goLang Hello !"
	str = strings.ToLower(str)
	fmt.Println(str)
	str = strings.ToUpper(str)
	fmt.Println(str)

	//str = strings.Trim(str, "! ")
	fmt.Println(str)

	str = strings.TrimLeft(str, "!")
	fmt.Println(str)

	prefix := strings.HasPrefix("http://www.baidu.com", "http") //true
	prefix1 := strings.HasPrefix("http://www.baidu.com", "tcp") //false
	fmt.Println(prefix, prefix1)

}
